var Sb = {
	Helpers:{
		
		Dialog:{
			dialogConfirmId: 'confirmDel',
			
			getConfirm: function(){
				return $('#'+this.dialogConfirmId);
			},
			
			initConfirm: function(){
				var $confirmDel = this.getConfirm();
				$confirmDel.dialog({
                    autoOpen: false,
			        resizable: false,
			        height:180,
                    width:340,
			        modal: true,
			        buttons: {
				        "Delete item": function() {
				        	Sb.Helpers.Delete.run();
				        	$confirmDel.dialog("close");
				        },
				        
				        Cancel: function() {
				        	$confirmDel.dialog("close");
				        }
			        }
		        });
			},
			
			init: function(){
				this.initConfirm();
			}
		},
		
		Delete:{
			btnClassName : 'del-btn',
			delId: null,
			delUrl: '',
			
			onComplete: function(dataFromServer){
				$('[data-id="'+this.delId+'"]:first').fadeOut('slow');
			},
			
			run: function(){
				var _self = this;
				$.ajax({
                    url: this.delUrl,
                	type: 'post',
                	dataType: 'json',
                	data:{id:this.delId},
                }).done(function(dataFromServer){
                	_self.onComplete(dataFromServer);
                });
			},
			
			init: function(baseUrl){
				this.delUrl = baseUrl+'/del';
				var _self = this;
				$('.'+this.btnClassName).button().on('click', function(){
					_self.delId = $(this).parents('[data-id]:first').data('id');
					Sb.Helpers.Dialog.getConfirm().dialog("open");
				});
			}
		},
		
		init: function(baseUrl){
			this.Delete.init(baseUrl);
			this.Dialog.init();
		}
	}
};